Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Combining two regex "^[\x20-\x7E]*$" and "\S(.*\S" into one

I have two regex that work separately: ^[\x20-\x7E]*$ and \S(.*\S

But I don't get how to combine the two so it will match them both.

I tried (^[\x20-\x7E]*$)*?(\S(.*\S)?) but it didn't work.

I used this in input tag with pattern="(^[\x20-\x7E]*$)*?(\S(.*\S)?)"

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Combine the two regexes with the pipe symbol. It is the same as the logical OR. Here's a code snippet demonstrating how to use this.

import re

regex_list = ["^[\x20-\x7E]$", "\S(.*\S)"]
regex = '|'.join(regex_list)

print(regex)                       # ^[ -~]$|\S(.*\S)
print(re.search(regex, "C"))       #matches first pattern
print(re.search(regex, "CAT CAT")) #matches second pattern
print(re.search(regex, " 3 "))     #matches neither pattern
about 4 years ago · Santiago Trujillo Report

0

One way to do this is to use word boundaries (\b) instead of the \S anchor:

^\b[\x20-\x7E]*\b$

This would match your given test case Priya@ #432, but would not match priya##23á or Priya@ #432 . You can see an example of this regex in action on Regex101 here.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!